package com.android.porttallymansystem.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.android.porttallymansystem.R
import com.android.porttallymansystem.logic.model.SystemMessage

class SystemMessageAdapter(private val systemMessageList: List<SystemMessage>) :
    RecyclerView.Adapter<SystemMessageAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tvTitle: TextView = view.findViewById(R.id.tv_system_message_title)
        val tvContent: TextView = view.findViewById(R.id.tv_system_message_content)
        val tvTime: TextView = view.findViewById(R.id.tv_system_message_time)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_system_message, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tvTitle.text = systemMessageList[position].title
        holder.tvContent.text = systemMessageList[position].content
        holder.tvTime.text = systemMessageList[position].time.toString()
    }

    override fun getItemCount() = systemMessageList.size
}